package org.crl.blogsystem.message;

import org.crl.blogsystem.entity.dto.BlogDTO;
import org.springframework.http.HttpStatus;

public class ResponseMessage<T> {
    private Integer code;
    private String message;
    private T data;

    public ResponseMessage(Integer code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    public static <T> ResponseMessage<T> success(T data) {
        return new ResponseMessage<>(HttpStatus.OK.value(), "success", data);
    }

    public static <T> ResponseMessage<T> exist() {
        return new ResponseMessage<>(HttpStatus.BAD_REQUEST.value(), "exist", null);
    }

    public static <T> ResponseMessage<T> fail() {
        return fail(HttpStatus.BAD_REQUEST.value(), "请求失败");
    }

    public static <T> ResponseMessage<T> fail(String message) {
        return new ResponseMessage<>(HttpStatus.BAD_REQUEST.value(), message, null);
    }

    public static <T> ResponseMessage<T> fail(int code, String message) {
        return new ResponseMessage<>(code, message, null);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
